﻿using CCWpf.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using static CCWpf.MsgBoxWindow;

namespace CCWpf.ViewModels
{
    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName]string propertyName="")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        /// <summary>
        /// 模式化打开窗口
        /// </summary>
        /// <param name="key"></param>
        /// <param name="objVM"></param>
        public void ShowDialog(string key, object objVM)
        {
            WindowManager.ShowWindow(key, objVM, true);
        }
        /// <summary>
        /// 非模式化打开窗口
        /// </summary>
        /// <param name="key"></param>
        /// <param name="objVM"></param>
        public void Show(string key, object objVM)
        {
            WindowManager.ShowWindow(key, objVM, false);
        }
        /// <summary>
        /// 关闭窗口
        /// </summary>
        /// <param name="key"></param>
        /// <param name="objVM"></param>
        public void CloseWindow(string key, object objVM)
        {
            WindowManager.CloseWindow(key, objVM);
        }
        /// <summary>
        /// 成功消息提示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <param name="buttons"></param>
        public void ShowSucess(string title, string msg, CustomMsgBoxButton buttons=CustomMsgBoxButton.Ok)
        { 
            MsgBoxWindow.Show(title, msg, buttons,CustomMsgBoxIcon.Infomation); 
        }

        /// <summary>
        /// 错误消息提示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <param name="buttons"></param>
        public void ShowError(string title, string msg, CustomMsgBoxButton buttons = CustomMsgBoxButton.Ok)
        {
            MsgBoxWindow.Show(title, msg, buttons, CustomMsgBoxIcon.Error);
        }

        /// <summary>
        /// 询问消息提示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <param name="buttons"></param>
        public CustomMsgBoxResult ShowQuestion(string title, string msg, CustomMsgBoxButton buttons = CustomMsgBoxButton.OkCancel)
        {
           return MsgBoxWindow.Show(title, msg, buttons, CustomMsgBoxIcon.Question);
        }

        private ICommand closeCmd;
        //关闭窗口命令
        public ICommand CloseCmd
        {
            get { return closeCmd; }
            set 
            { 
                closeCmd = value;  
            }
        }
        /// <summary>
        /// 生成对应窗口命令
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public ICommand CloseWinCmd(string key)
        {
            return new RelayCommand(oWin => {
                CloseWindow(key, oWin);
            });
        }
        /// <summary>
        ///  生成窗口拖动命令
        /// </summary>
        /// <returns></returns>
        public RelayCommand CreateMoveWinCmd()
        {
            return new RelayCommand(o=> {
               Window win = o as Window;
               win?.DragMove();
            });
        }
        /// <summary>
        /// 生成名称信息的拼音码
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetPinYin(string name)
        { 
            return PinYinHelper.GetFirstSpell(name);
        }
    }
}
